home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Examples / MiscString / stest2.m < prev    next >
Encoding:
Text File  |  1995-04-12  |  1.9 KB  |  64 lines

  1. //        Written by Carl Lindberg Copyright (c) 1994 by Carl Lindberg.
  2. //                Version 1.0.  All rights reserved.
  3. //
  4. //        This notice may not be removed from this source code.
  5. //
  6. //    This program is included in the MiscKit by permission from the author
  7. //    and its use is governed by the MiscKit license, found in the file
  8. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  9. //    for a list of all applicable permissions and restrictions.
  10. //    
  11.  
  12. #import "mscarl.h"
  13.  
  14. char *names[12] = {
  15.                      "MISC_UPPER",
  16. "MISC_LOWER",
  17. "MISC_DIGIT",
  18. "MISC_XDIGIT",
  19. "MISC_PUNCT",
  20. "MISC_ASCII",
  21. "MISC_CNTRL",
  22. "MISC_PRINT",
  23. "MISC_SPACE",
  24. "MISC_GRAPH",
  25. "MISC_ALPHA",
  26. "MISC_ALNUM"
  27. };
  28.  
  29. int values[12] = {1,2,4,8,16,32,64,128,256,512,3,7};
  30.  
  31. #define NUMSTRS 2
  32.  
  33. char *strs[NUMSTRS] = { "Hello my dear [] 345 How ''are78 we?",
  34.                   "OH! DARLING"
  35. };
  36.  
  37.  
  38. void main()
  39. {
  40.   int i,j,k,l;
  41.   id str = [MiscString new];
  42.  
  43.   for (i=0;i<NUMSTRS;i++) {
  44.     printf("------------------------------------------------\n");
  45.     printf("String is: <%s>\n",strs[i]);
  46.     [str setStringValue:strs[i]];
  47.     for (j=0;j<12;j++) {
  48.       printf("Is all %s? %d\n",names[j],[str isAllOfType:values[j]]); 
  49.       printf("Has    %s? %d\n",names[j],[str hasType:values[j]]);
  50.       printf("Num of %s: %d\n",names[j],[str numOfType:values[j]]);
  51.       printf("spotsof %s: ",names[j]);
  52.       for (k=0;(l=[str spotOfType:values[j] occurrenceNum:k])>=0;k++) printf("%d ",l);
  53.       printf("\n");
  54.       printf("rspotsof %s: ",names[j]);
  55.       for (k=0;(l=[str rspotOfType:values[j] occurrenceNum:k])>=0;k++) printf("%d ",l);
  56.       printf("\n");
  57.       for (k=-1;k<5;k++) printf("replace %dth %s with '*': <%s>\n",k,names[j],
  58. [[[str copy] replaceType:values[j] withChar:'*' occurrenceNum:k] stringValueAndFree]);
  59.       printf("replaceAll %s with '*': <%s>\n",names[j],[[[str copy] replaceEveryOccurrenceOfType:values[j] withChar:'*'] stringValueAndFree]);
  60.      }
  61.    }
  62.  [str free];
  63. }
  64.